package zy.ejb;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import zy.jpa.PersonDAO;

public class EJBFactory {

	public static HelloRemote getJboss7SessionEJB_remote() throws NamingException {

		HelloRemote helloworld = null; 
		final Hashtable jndiProperties = new Hashtable(); 
		jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
		final Context context = new InitialContext(jndiProperties); 
		final String appName = "ear1"; 
		final String moduleName = "ejb1";// 工程名 
		final String distinctName = ""; 
		final String beanName = "Hello";  
		String jndi = "ejb:" + appName + "/" + moduleName + "/" + distinctName
				+ "/" + beanName + "!" + HelloRemote.class.getName(); 

		helloworld = (HelloRemote) context.lookup(jndi);

		return helloworld;

	}
	
	public static PersonDAO getJboss7SessionEJB_DAO() throws NamingException {

		PersonDAO retDAO = null; 
		final Hashtable jndiProperties = new Hashtable(); 
		jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
		final Context context = new InitialContext(jndiProperties); 
		final String appName = "ear1"; 
		final String moduleName = "ejb1";// 工程名 
		final String distinctName = ""; 
		final String beanName = "PersonDAOBean";  
		String jndi = "ejb:" + appName + "/" + moduleName + "/" + distinctName
				+ "/" + beanName + "!" + PersonDAO.class.getName(); 

		retDAO = (PersonDAO) context.lookup(jndi);

		return retDAO;

	}
	
	
	
	public static HelloLocal getJboss7SessionEJB_local() throws NamingException {

		HelloLocal helloworld = null; 
		final Hashtable jndiProperties = new Hashtable(); 
		jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
		final Context context = new InitialContext(jndiProperties); 
		final String appName = "ear1"; 
		final String moduleName = "ejb1";// 工程名 
		final String distinctName = ""; 
		final String beanName = "Hello";  
		String jndi = "ejb:" + appName + "/" + moduleName + "/" + distinctName
				+ "/" + beanName + "!" + HelloLocal.class.getName(); 

		helloworld = (HelloLocal) context.lookup(jndi);

		return helloworld;

	}
}
